data "alicloud_instances" "cloudiac" {
  name_regex = "iac_autoscale_"
  status     = "Running"
}

output "ecs" {
  value = data.alicloud_instances.cloudiac
}

resource "alicloud_slb_server_group" "cloudiac_server_group" {
  load_balancer_id = var.load_balancer_id
  name             = "cloudiac_server_group"
  servers {
    server_ids = data.alicloud_instances.cloudiac.instances.*.id
    port       = "80"
    weight     = 50
  }
}

resource "alicloud_slb_listener" "default" {
  load_balancer_id          = var.load_balancer_id
  backend_port              = "80"
  frontend_port             = "80"
  protocol                  = "tcp"
  bandwidth                 = 10
  scheduler                 = "rr"
  server_group_id =  alicloud_slb_server_group.cloudiac_server_group.id
}
